import Timeago from 'timeago.js'


export default {

	methods: {

		formatTabBtn(top, good, tab, isClass) {
			let str = '';
			let className = '';
			if (top) {
				str = '置顶';
				className = 'g-bgTop';
			} else if (good) {
				str = '精华';
				className = 'g-bgGood';
			} else {
				switch (tab) {
					case 'share':
						str = '分享';
						className = 'g-bgShare';
						break;
					case 'ask':
						str = '问答';
						className = 'g-bgAsk';
						break;
					case 'job':
						str = '招聘';
						className = 'g-bgJob';
						break;
					default:
						str = '暂无';
						className = 'g-bgDefault';
						break;
				}
			}
			return isClass ? className : str;
		},

		formatTime(time) {
			if (time) {
				var str = '',
					date = new Date(time);
				var o = {
					'N+': date.getFullYear(), //年
					'M+': date.getMonth() + 1, // 月份
					'd+': date.getDate(), // 日
					'h+': date.getHours(), // 小时
					'm+': date.getMinutes(), // 分
					's+': date.getSeconds(), // 秒
					'S': date.getMilliseconds() // 毫秒
				};

				str += o['N+'] + '-';
				str += o['M+'] + '-';
				str += o['d+'] + ' ';
				str += o['h+'] + ':';
				str += o['m+'];
				return str;
			}
		},

		formatCountDownTime(time) {
			if (time) {
				let str = '',
					timeagoInstance = new Timeago();
				str = timeagoInstance.format(time, 'zh_CN');
				return str;
			}
		}

	}

}
